package demo1;

import java.util.Random;
import java.util.Scanner;

public class demo_9 {
    public static int[] getSum(int[] a, int[] b){
        int[] c ={0, 0};
        for (int i = 0; i < 6; i++){
            if (a[i] == b[i]){
                c[0]++;
            }
        }
        if (a[6] == b[6])c[1]++;
        return c;
    }
    public static int[] setNumber(){
        Random r = new Random();
        int[] a = new int[7];
        for (int i = 0; i < 6; i++){
            a[i] = r.nextInt(33) + 1;
        }
        a[6] = r.nextInt(16) + 1;
        return a;
    }
    public static void towBall(){
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int[] a = new int[7];
        int[] b = setNumber();
        int[] sum;
        //用户输入购买号码
        System.out.println("请输入购买号码：");
        //处理红球
        for (int i = 0; i < 6; i++){
            while (true) {
                int c = sc.nextInt();
                if (c >= 1 && c <= 33){
                    a[i] = c;
                    break;
                }
                else{
                    System.out.println("输入错误：红球的号码在1~33之间");
                }
            }
        }
        //处理篮球
        while (true) {
            int c = sc.nextInt();
            if (c >= 1 && c <= 16){
                a[6] = c;
                break;
            }
            else{
                System.out.println("输入错误：蓝球的号码在1~16之间");
            }
        }
        //得到中奖情况
        sum = getSum(a, b);
        //判断中奖情况
        System.out.println("中奖号码为：");
        for (int i = 0; i < 7; i++) System.out.print(b[i] + " ");
        switch(sum[1]){
            case 1:
                switch(sum[0]){
                    case 6:
                        System.out.println("一等奖");
                        break;
                    case 5:
                        System.out.println("三等奖");
                        break;
                    case 4:
                        System.out.println("四等奖");
                        break;
                    case 3:
                    case 2:
                        System.out.println("五等奖");
                        break;
                    case 1:
                    case 0:
                        System.out.println("六等奖");
                }
                break;
            case 0:
                switch(sum[0]){
                    case 6:
                        System.out.println("二等奖");
                        break;
                    case 5:
                        System.out.println("三等奖");
                        break;
                    case 4:
                        System.out.println("四等奖");
                        break;
                    default:
                        System.out.println("恒遗憾，你没有中奖~~~");
                }
        }

    }
    public static void main(String[] args) {
        towBall();

    }
}
